package com.zmn.oms.services.impl.redistribute;

import com.zmn.oms.model.entity.redistribute.OrderWorkRedistributeMaster;
import com.zmn.oms.persistence.interfaces.redistribute.OrderWorkRedistributeMasterDao;
import com.zmn.oms.services.interfaces.redistribute.OrderWorkRedistributeMasterService;
import io.shardingsphere.api.HintManager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class OrderWorkRedistributeMasterServiceImpl implements OrderWorkRedistributeMasterService {

    @Resource
    OrderWorkRedistributeMasterDao orderWorkRedistributeMasterDao;

    @Override
    public OrderWorkRedistributeMaster selectByPrimaryKey(Long id) {
        return orderWorkRedistributeMasterDao.selectByPrimaryKey(id);
    }

    @Override
    public List<OrderWorkRedistributeMaster> selectByQuery(OrderWorkRedistributeMaster query) {
        return orderWorkRedistributeMasterDao.selectByQuery(query);
    }

    @Override
    public List<OrderWorkRedistributeMaster> selectByQuerySrcMaster(OrderWorkRedistributeMaster query) {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.setMasterRouteOnly();
            return orderWorkRedistributeMasterDao.selectByQuery(query);
        }
    }

    @Override
    public int delete(Long id) {
        return orderWorkRedistributeMasterDao.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(OrderWorkRedistributeMaster record) {
        return orderWorkRedistributeMasterDao.insertSelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(OrderWorkRedistributeMaster record) {
        return orderWorkRedistributeMasterDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public Integer batchInsert(List<OrderWorkRedistributeMaster> redistributeMasterList) {
        return orderWorkRedistributeMasterDao.batchInsert(redistributeMasterList);
    }

    @Override
    public Integer updateStatusByRedistributeId(Long redistributeId, int status) {
        return orderWorkRedistributeMasterDao.updateStatusByRedistributeId(redistributeId, status);
    }

    @Override
    public OrderWorkRedistributeMaster findByRedistributeIdAndMasterId(Long redistributeId, Integer masterId) {
        return orderWorkRedistributeMasterDao.findByRedistributeIdAndMasterId(redistributeId, masterId);
    }

    @Override
    public Integer deleteByCreateTimeAndStatus(Date createTime, int status) {
        return orderWorkRedistributeMasterDao.deleteByCreateTimeAndStatus(createTime, status);
    }
}